home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / ext2_200.zip / EXT2_SRC.ZIP / 32BITS / EXT2-OS2 / FSD32 / FS32_FSI.C < prev    next >
C/C++ Source or Header  |  1996-09-21  |  7KB  |  187 lines

  1. //
  2. // $Header: D:/32bits/ext2-os2/fsd32/RCS/fs32_fsinfo.c,v 1.1 1996/09/21 22:25:15 Willm Exp Willm $
  3. //
  4.  
  5. // 32 bits Linux ext2 file system driver for OS/2 WARP - Allows OS/2 to
  6. // access your Linux ext2fs partitions as normal drive letters.
  7. // Copyright (C) 1995, 1996 Matthieu WILLM
  8. //
  9. // This program is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation; either version 2 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #ifdef __IBMC__
  23. #pragma strings(readonly)
  24. #endif
  25.  
  26.  
  27. #define INCL_DOS
  28. #define INCL_DOSERRORS
  29. #define INCL_NOPMAPI
  30. #include <os2.h>
  31.  
  32. #include <string.h>
  33.  
  34. #include <os2/types.h>
  35. #include <os2/StackToFlat.h>
  36. #include <linux/fs.h>
  37. #include <os2/os2proto.h>
  38. #include <os2/fsd32.h>
  39. #include <os2/fsh32.h>
  40. #include <os2/DevHlp32.h>
  41. #include <os2/log.h>
  42. #include <os2/trace.h>
  43. #include <os2/errors.h>
  44. #include <os2/files.h>
  45. #include <os2/volume.h>
  46. #include <linux/fs_proto.h>
  47. #include <linux/stat.h>
  48. #include <os2/vfsapi.h>
  49. #include <os2/ifsdbg.h>
  50.  
  51. struct FSINFO16 {        /* fsinf */
  52.     ULONG ulVSN;
  53.     VOLUMELABEL vol;
  54. };
  55.  
  56. /*
  57.  * struct fs32_fsinfo_parms {
  58.  *     unsigned short level;
  59.  *     unsigned short cbData;
  60.  *     PTR16          pData;
  61.  *     unsigned short hVPB;
  62.  *     unsigned short flag;
  63.  * };
  64.  */
  65. int FS32ENTRY fs32_fsinfo(struct fs32_fsinfo_parms *parms) {
  66.     char           *pData;
  67.     int             rc;
  68.     int             rc2;
  69.  
  70.     FSALLOCATE        *pfsil_alloc;
  71.     struct super_block *            sb;
  72.     struct ext2_super_block       *psb;
  73.     struct vpfsi32 *pvpfsi;
  74.     union  vpfsd32 *pvpfsd;
  75.     PTR16  pvpfsi16;
  76.     PTR16  pvpfsd16;
  77.     struct FSINFO16 *pvolser;
  78.     char lock[12];
  79.     unsigned long PgCount;
  80.  
  81.     parms = __StackToFlat(parms);
  82.  
  83.     if ((rc = DevHlp32_VirtToLin(parms->pData, __StackToFlat(&pData))) == NO_ERROR) {
  84.     /*******************************************************************/
  85.     /*** Traitement des cas suivant flag (INFO_RETRIEVE - INFO_SET)  ***/
  86.     /*******************************************************************/
  87.     switch(parms->flag) {
  88.         /*******************************************************************/
  89.         /*** INFO_RETRIEVE : retrieves file system information           ***/
  90.         /*******************************************************************/
  91.         case INFO_RETREIVE :
  92.             switch(parms->level) {
  93.                 case FSIL_VOLSER :
  94. #ifdef FS_TRACE
  95.                     if ((rc = fs_log("FS_FSINFO : flag = INFO_RETREIVE, level = FSIL_VOLSER")) != NO_ERROR) {
  96.                         return rc;
  97.                     } /* end if */
  98. #endif
  99.                     if ((rc = fsh32_getvolparm(parms->hVPB, __StackToFlat(&pvpfsi16), __StackToFlat(&pvpfsd16))) == NO_ERROR) {
  100.                         if ((rc = DevHlp32_VirtToLin(pvpfsi16, __StackToFlat(&pvpfsi))) == NO_ERROR) {
  101.                         if ((rc = DevHlp32_VirtToLin(parms->pData, __StackToFlat(&pData))) == NO_ERROR) {
  102.  
  103.                             rc = DevHlp32_VMLock(VMDHL_LONG | VMDHL_VERIFY | VMDHL_WRITE, pData, sizeof(struct FSINFO16), (void *)-1, __StackToFlat(lock), __StackToFlat(&PgCount));
  104.                             if ((rc == NO_ERROR) || (rc == ERROR_NOBLOCK)) {
  105.  
  106.                                 pvolser          = (struct FSINFO16 *)pData;
  107.                                 pvolser->ulVSN   = pvpfsi->vpi_vid;
  108.                                 pvolser->vol.cch = (BYTE)strlen(pvpfsi->vpi_text);
  109.                                 strcpy(pvolser->vol.szVolLabel, pvpfsi->vpi_text);
  110.                                 rc = NO_ERROR;
  111.  
  112.                     if ((rc2 = DevHlp32_VMUnlock(__StackToFlat(lock))) == NO_ERROR) {
  113.                                 } else {
  114.                            rc = rc2;
  115.                                 }
  116.  
  117.                     }
  118.  
  119.                         }
  120.                         }
  121.                     }
  122.             break;
  123.  
  124.                 case FSIL_ALLOC :
  125. #ifdef FS_TRACE
  126.                     if ((rc = fs_log("FS_FSINFO : flag = INFO_RETREIVE, level = FSIL_ALLOC")) != NO_ERROR) {
  127.                         return rc;
  128.                     } /* end if */
  129. #endif
  130.                         if ((rc = DevHlp32_VirtToLin(parms->pData, __StackToFlat(&pData))) == NO_ERROR) {
  131.  
  132.                             rc = DevHlp32_VMLock(VMDHL_LONG | VMDHL_VERIFY | VMDHL_WRITE, pData, sizeof(FSALLOCATE), (void *)-1, __StackToFlat(lock), __StackToFlat(&PgCount));
  133.                             if ((rc == NO_ERROR) || (rc == ERROR_NOBLOCK)) {
  134.                     sb = getvolume(parms->hVPB);
  135.                     psb = (struct ext2_super_block *)sb->u.ext2_sb.s_sbh->b_data;
  136.                     pfsil_alloc = (FSALLOCATE *)pData;
  137. //                  pfsil_alloc->idFileSystem      =  ????? ;
  138.                     pfsil_alloc->cSectorUnit       = sb->sectors_per_block;
  139.                     pfsil_alloc->cUnit             = psb->s_blocks_count;
  140.                     pfsil_alloc->cUnitAvail        = (psb->s_free_blocks_count > psb->s_r_blocks_count ? psb->s_free_blocks_count - psb->s_r_blocks_count : 0);
  141.                     pfsil_alloc->cbSector          = (UINT16)sb->sector_size;
  142.                     rc = NO_ERROR;
  143.                     if ((rc2 = DevHlp32_VMUnlock(__StackToFlat(lock))) == NO_ERROR) {
  144.                                 } else {
  145.                            rc = rc2;
  146.                                 }
  147.  
  148.                     }
  149.  
  150.                         }
  151.  
  152.             break;
  153.  
  154.                 default :
  155.                     rc = ERROR_INVALID_PARAMETER;
  156.             break;
  157.             }
  158.             break;
  159.         /*******************************************************************/
  160.  
  161.         /*******************************************************************/
  162.         /*** INFO_SET : used to set the volume label and volume serial   ***/
  163.         /***            number. We currently do nothing                  ***/
  164.         /*******************************************************************/
  165.         case INFO_SET :
  166. #ifdef FS_TRACE
  167.             kernel_printf("FS_FSINFO(INFO_SET)");
  168. #endif
  169.             if (Read_Write) {
  170.                 rc = NO_ERROR;
  171.             } else {
  172.                 rc = ERROR_WRITE_PROTECT;
  173.             }
  174.         /*******************************************************************/
  175.  
  176.         /*******************************************************************/
  177.         /*** Unknown flag                                                ***/
  178.         /*******************************************************************/
  179.         default :
  180.             rc = ERROR_INVALID_PARAMETER;
  181.         break;
  182.         /*******************************************************************/
  183.     }
  184.     }
  185.     return rc;
  186. }
  187.